<?php
class Jnd_Mail extends \Zend_Mail
{

    /**
     * On construit un mail en fonctionne de l'environnement de l'application du
     * application.ini
     * 
     * @see Zend_Mail::__construct()
     */
    public function __construct( $charset = null )
    {
        $mailConfig = Jnd_App::getConfig("alert");
        if (isset($mailConfig['mail']['options']) && is_array($mailConfig['mail']['options'])) {
            $options = $mailConfig['mail']['options'];
        } else {
            $options = array();
        }
        if (isset($options['ssl']) && !$options['ssl']) {
            unset($options['ssl']);
        }
        
        $transport = new Zend_Mail_Transport_Smtp($mailConfig['mail']['server'], $options);
        $this->setDefaultTransport($transport);
        parent::__construct($charset);
    }

    /**
     * 
     * @param unknown_type $charset
     * @return Jnd_Mail|Zend_Mail
     */
    public static function factory( $charset = null )
    {
        $env = APPLICATION_ENV;
        $class = "Jnd_Mail_" . ucfirst($env);
        return new $class($charset);
    }
}

